home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-13 | 49.1 KB | 2,198 lines |
- Newsgroups: comp.sources.misc
- From: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
- Subject: v29i098: zsh2.2 - The Z shell, Part02/17
- Message-ID: <1992May13.155328.7924@sparky.imd.sterling.com>
- X-Md4-Signature: 2f21b032838f030851ae938e2335ae85
- Date: Wed, 13 May 1992 15:53:28 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
- Posting-number: Volume 29, Issue 98
- Archive-name: zsh2.2/part02
- Environment: BSD
- Supersedes: zsh2.1: Volume 24, Issue 1-19
-
- #!/bin/sh
- # this is aa.02 (part 2 of zsh2.2)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file zsh2.2/doc/intro.txt continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 2; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping zsh2.2/doc/intro.txt'
- else
- echo 'x - continuing file zsh2.2/doc/intro.txt'
- sed 's/^X//' << 'SHAR_EOF' >> 'zsh2.2/doc/intro.txt' &&
- Xother hand, is replaced with the output itself.) print -l is
- Xlike echo, excepts that it prints its arguments one per
- Xline, the way fgrep expects them:
- X
- X% print -l foo bar
- Xfoo
- Xbar
- X
- X
- XWe could also have written:
- X
- X% who | fgrep -f =(echo 'root
- X> lemke
- X> shgchan
- X> subbarao')
- X
- X
- XUsing process substitution, you can edit the output of a
- Xcommand:
- X
- X% ed =(who | fgrep -f ~/.friends)
- X355
- Xg/lemke/d
- Xw /tmp/filbar
- X226
- Xq
- X% cat /tmp/filbar
- Xroot console May 19 10:41
- Xshgchan ttys1 May 23 16:52 (gaudi.Princeton.)
- Xsubbarao ttyt7 May 23 15:02 (mad55sx15.Prince)
- Xsubbarao ttyu6 May 23 15:04 (mad55sx15.Prince)
- Xshgchan ttyvb May 23 16:51 (gaudi.Princeton.)
- X
- X
- Xor easily read archived mail:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 16 -
- X
- X% mail -f =(zcat ~/mail/oldzshmail.Z)
- X"/tmp/zsha06024": 84 messages, 0 new, 43 unread
- X> 1 U TO: pfalstad, zsh (10)
- X 2 U nytim!tim@uunet.uu.net, Re: Zsh on Sparc1 /SunOS 4.0.3
- X 3 U JAM%TPN@utrcgw.utc.com, zsh fix (15)
- X 4 U djm@eng.umd.edu, way to find out if running zsh? (25)
- X 5 U djm@eng.umd.edu, Re: way to find out if running zsh? (17)
- X 6 r djm@eng.umd.edu, Meta . (18)
- X 7 U jack@cs.glasgow.ac.uk, Re: problem building zsh (147)
- X 8 U nytim!tim@uunet.uu.net, Re: Zsh on Sparc1 /SunOS 4.0.3
- X 9 ursa!jmd, Another fix... (61)
- X 10 U pplacewa@bbn.com, Re: v18i084: Zsh 2.00 - A small complaint (36)
- X 11 U lubkin@cs.rochester.edu, POSIX job control (34)
- X 12 U yale!bronson!tan@uunet.UU.NET
- X 13 U brett@rpi.edu, zsh (36)
- X 14 S subbarao, zsh sucks!!!! (286)
- X 15 U snibru!d241s008!d241s013!ala@relay.EU.net, zsh (165)
- X 16 U nytim!tim@uunet.UU.NET, Re: Zsh on Sparc1 /SunOS 4.0.3
- X 17 U subbarao, zsh is a junk shell (43)
- X 18 U amaranth@vela.acs.oakland.edu, zsh (33)
- X43u/84 1: x
- X% ls -l /tmp/zsha06024
- X/tmp/zsha06024 not found
- X
- X
- XNote that the shell creates a temporary file, and deletes it
- Xwhen the command is finished.
- X
- X% diff =(ls) =(ls -F)
- X3c3
- X< fortune
- X---
- X> fortune*
- X10c10
- X< strfile
- X---
- X> strfile*
- X
- X
- XIf you read zsh's man page, you may notice that <(...) is
- Xanother form of process substitution which is similar to
- X=(...). There is an important difference between the two.
- XIn the <(...) case, the shell creates a named pipe (FIFO)
- Xinstead of a file. This is better, since it does not fill
- Xup the file system; but it does not work in all cases. In
- Xfact, if we had replaced =(...) with <(...) in the examples
- Xabove, all of them would have stopped working except for
- Xfgrep -f <(...). You can not edit a pipe, or open it as a
- Xmail folder; fgrep, however, has no problem with reading a
- Xlist of words from a pipe. You may wonder why diff <(foo)
- Xbar doesn't work, since foo | diff - bar works; this is
- Xbecause diff creates a temporary file if it notices that one
- Xof its arguments is -, and then copies its standard input to
- Xthe temporary file.
- X
- XAliasing
- X
- XOften-used commands can be abbreviated with an alias:
- X
- X
- X
- X
- X
- X
- X - 17 -
- X
- X% alias uc=uncompress
- X% ls
- Xhanoi.Z
- X% uc hanoi
- X% ls
- Xhanoi
- X
- X
- Xor commands with certain desired options:
- X
- X% alias fm='finger -m'
- X% fm root
- XLogin name: root In real life: Operator
- XDirectory: / Shell: /bin/csh
- XOn since May 19 10:41:15 on console 3 days 5 hours Idle Time
- XNo unread mail
- XNo Plan.
- X
- X% alias lock='lock -p -60000'
- X% lock
- Xlock: /dev/ttyr4 on phoenix. timeout in 60000 minutes
- Xtime now is Fri May 24 04:23:18 EDT 1991
- XKey:
- X
- X% alias l='ls -AF'
- X% l /
- X.bash_history kadb*
- X.bashrc lib@
- X.cshrc licensed/
- X.exrc lost+found/
- X.login macsyma
- X
- X
- XAliases can also be used to replace old commands:
- X
- X% alias grep=egrep ps=sps make=gmake
- X% alias whoami='echo root'
- X% whoami
- Xroot
- X
- X
- Xor to define new ones:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 18 -
- X
- X% cd /
- X% alias sz='ls -l | sort -n +3 | tail -10'
- X% sz
- Xdrwxr-sr-x 7 bin 3072 May 23 11:59 etc
- Xdrwxrwxrwx 26 root 5120 May 24 04:20 tmp
- Xdrwxr-xr-x 2 root 8192 Dec 26 19:34 lost+found
- Xdrwxr-sr-x 2 bin 14848 May 23 18:48 dev
- X-r--r--r-- 1 root 140520 Dec 26 20:08 boot
- X-rwxr-xr-x 1 root 311172 Dec 26 20:08 kadb
- X-rwxr-xr-x 1 root 1209695 Apr 16 15:33 vmunix.old
- X-rwxr-xr-x 1 root 1209702 May 14 19:04 vmunix
- X-rwxr-xr-x 1 root 1209758 May 21 12:23 vmunix.new.kernelmap.old
- X-rwxr-xr-x 1 root 1711848 Dec 26 20:08 vmunix.org
- X% cd
- X% alias rable='ls -AFtrd *(R)' nrable='ls -AFtrd *(^R)'
- X% rable
- XREADME func/ bin/ pub/ News/ src/
- Xnicecolors etc/ scr/ tmp/ iris/ zsh*
- X% nrable
- XMailboxes/ mail/ notes
- X
- X
- X(The pattern *(R) matches all readable files in the current
- Xdirectory, and *(^R) matches all unreadable files.)
- X
- XMost other shells have aliases of this kind (command
- Xaliases). However, zsh also has global aliases, which are
- Xsubstituted anywhere on a line. Global aliases can be used
- Xto abbreviate frequently-typed usernames, hostnames, etc.
- X
- X% alias -g me=pfalstad gun=egsirer mjm=maruchck
- X% who | grep me
- Xpfalstad ttyp0 May 24 03:39 (mickey.Princeton)
- Xpfalstad ttyp5 May 24 03:42 (mickey.Princeton)
- X% fm gun
- XLogin name: egsirer In real life: Emin Gun Sirer
- XDirectory: /u/egsirer Shell: /bin/sh
- XLast login Thu May 23 19:05 on ttyq3 from bow.Princeton.ED
- XNew mail received Fri May 24 02:30:28 1991;
- X unread since Fri May 24 02:30:27 1991
- X% alias -g phx=phoenix.princeton.edu warc=wuarchive.wustl.edu
- X% ftp warc
- XConnected to wuarchive.wustl.edu.
- X
- X
- XHere are some more interesting uses.
- X
- X% alias -g M='| more' GF='| fgrep -f ~/.friends'
- X% who M # pipes the output of who through more
- X% who GF # see if your friends are on
- X% w GF # see what your friends are doing
- X
- X
- XAnother example makes use of zsh's process substitution. If
- Xyou run NIS, and you miss being able to do this:
- X
- X% grep pfalstad /etc/passwd
- X
- X
- X
- X
- X
- X
- X
- X - 19 -
- Xyou can define an alias that will seem more natural than
- Xypmatch pfalstad passwd:
- X
- X% alias -g PASS='<(ypcat passwd)'
- X% grep pfalstad PASS
- Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
- X
- X
- XIf you're really crazy, you can even call it /etc/passwd:
- X
- X% alias -g /etc/passwd='<(ypcat passwd)'
- X% grep pfalstad /etc/passwd
- Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
- X
- X
- XThe last example shows one of the perils of global aliases;
- Xthey have a lot of potential to cause confusion. For exam-
- Xple, if you defined a global alias called | (which is possi-
- Xble), zsh would begin to act very strangely; every pipe sym-
- Xbol would be replaced with the text of your alias. To some
- Xextent, global aliases are like macros in C; discretion is
- Xadvised in using them and in choosing names for them. Using
- Xnames in all caps is not a bad idea, especially for aliases
- Xwhich introduce shell metasyntax (like M and GF above).
- X
- XNote that zsh aliases are not like csh aliases. The syntax
- Xfor defining them is different, and they do not have argu-
- Xments. All your favorite csh aliases will probably not work
- Xunder zsh. For example, if you try:
- X
- Xalias rm mv '\!* /tmp/wastebasket'
- X
- X
- Xno aliases will be defined, but zsh will not report an
- Xerror. In csh, this line defines an alias that makes rm
- Xsafe---files that are rm'd will be moved to a temporary
- Xdirectory instead of instantly destroyed. In zsh's syntax,
- Xhowever, this line asks the shell to print any existing
- Xalias definitions for rm, mv, or !* /tmp/wastebasket. Since
- Xthere are none, most likely, the shell will not print any-
- Xthing, although alias will return a nonzero exit code. The
- Xproper syntax is this:
- X
- Xalias rm='mv \!* /tmp/wastebasket'
- X
- X
- XHowever, this won't work either:
- X
- X% rm foo.dvi
- Xzsh: no matches found: !*
- X
- X
- XWhile this makes rm safe, it is certainly not what the user
- Xintended. In zsh, you must use a shell function for this:
- X
- X% unalias rm
- X% rm () { mv $* /tmp/wastebasket }
- X% rm foo.dvi
- X% ls /tmp/wastebasket
- Xfoo.dvi
- X
- X
- X
- X
- X
- X - 20 -
- XWhile this is much cleaner and easier to read (I hope you
- Xwill agree), it is not csh-compatible. Therefore, a script
- Xto convert csh aliases and variables has been provided. You
- Xshould only need to use it once, to convert all your csh
- Xaliases and parameters to zsh format:
- X
- X% csh
- Xcsh> alias
- Xl ls -AF
- Xmore less
- Xon last -2 !:1 ; who | grep !:1
- Xcsh> exit
- X% c2z >neat_zsh_aliases
- X% cat neat_zsh_aliases
- Xalias l='ls -AF'
- Xalias more='less'
- Xon () { last -2 $1 ; who | grep $1 }
- X...
- X
- X
- XThe first two aliases were converted to regular zsh aliases,
- Xwhile the third, since it needed to handle arguments, was
- Xconverted to a function. c2z can convert most aliases to
- Xzsh format without any problems. However, if you're using
- Xsome really arcane csh tricks, or if you have an alias with
- Xa name like do (which is reserved in zsh), you may have to
- Xfix some of the aliases by hand.
- X
- XThe c2z script checks your csh setup, and produces a list of
- Xzsh commands which replicate your aliases and parameter set-
- Xtings as closely as possible. You could include its output
- Xin your startup file, .zshrc.
- X
- XHistory
- X
- XThere are several ways to manipulate history in zsh. One
- Xway is to use csh-style ! history:
- X
- X% /usr/local/bin/!:0 !-2*:s/foo/bar/ >>!$
- X
- X
- XIf you don't want to use this, you can turn it off by typing
- Xsetopt nobanghist.
- X
- XAnother way is to use the fc command. For example, if you
- Xtype an erroneous command:
- X
- X% for i in `cat /etc/clients`
- X do
- X rpu $i
- X done
- Xzsh: command not found: rpu
- Xzsh: command not found: rpu
- Xzsh: command not found: rpu
- X
- X
- Xtyping fc will execute an editor on this command, allowing
- Xyou to fix it. (The default editor is vi, by the way, not
- Xed).
- X
- X
- X
- X
- X
- X
- X - 21 -
- X
- X% fc
- X49
- X/rpu/s//rup/p
- X rup $i
- Xw
- X49
- Xq
- Xfor i in `cat /etc/clients`
- X do
- X rup $i
- X done
- X beam up 2 days, 10:17, load average: 0.86, 0.80, 0.50
- X bow up 4 days, 8:41, load average: 0.91, 0.80, 0.50
- X burn up 17:18, load average: 0.91, 0.80, 0.50
- X burst up 9 days, 1:49, load average: 0.95, 0.80, 0.50
- X tan up 11:14, load average: 0.91, 0.80, 0.50
- X bathe up 3 days, 17:49, load average: 1.84, 1.79, 1.50
- X bird up 1 day, 9:13, load average: 1.95, 1.82, 1.51
- X bonnet up 2 days, 21:18, load average: 0.93, 0.80, 0.50
- X
- X
- XA variant of the fc command is r, which redoes the last com-
- Xmand, with optional changes:
- X
- X% echo foo
- Xfoo
- X% r
- Xecho foo
- Xfoo
- X
- X% echo foo
- Xfoo
- X% r foo=bar
- Xecho bar
- Xbar
- X
- X
- X
- XCommand Line Editing
- X
- Xzsh's command line editor, ZLE, is quite powerful. It is
- Xdesigned to emulate either emacs or vi; the default is
- Xemacs. To set the bindings for vi mode, type bindkey -v.
- X
- XIn addition to basic editing, the shell allows you to recall
- Xprevious lines in the history. In emacs mode, this is done
- Xwith ^P (control-P):
- X
- X% ls ~
- X- README file mail pub tmp
- XMailboxes bin func nicecolors scr zsh
- XNews etc iris notes src
- X% echo foobar
- Xfoobar
- X% ^P
- X% echo foobar^P
- X% ls ~_
- X
- X
- X
- X
- X
- X
- X
- X - 22 -
- XPressing ^P once brings up the previous line (echo foobar);
- Xpressing it again brings up the line before that (ls ~).
- XThe cursor is left at the end of the line, allowing you to
- Xedit the line if desired before executing it. In many
- Xcases, ZLE eliminates the need for the fc command, since it
- Xis powerful enough to handle even multiline commands:
- X
- X% for i in a b c d e
- X> do
- X> echo $i
- X> done
- Xa
- Xb
- Xc
- Xd
- Xe
- X% ^P
- X% for i in a b c d e
- X do
- X echo $i
- X done_
- X
- X
- XNow you can just move up to the part you want to change...
- X
- X% for i in _ b c d e
- X do
- X echo $i
- X done
- X
- X
- Xchange it, and execute the new command.
- X
- X% for i in f g h i j
- X do
- X echo $i
- X done
- Xf
- Xg
- Xh
- Xi
- Xj
- X
- X
- XAlso, you can search the history for a certain command using
- XESC-P:
- X
- X% set ESC-P
- X% setopt autolist ESC-P
- X% setopt nocorrect_
- X
- X
- XAnother way is to do an incremental search, emacs-style:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 23 -
- X
- X% ^R
- X% _
- Xi-search:
- X
- X% l_ /usr/bin
- Xi-search: l
- X
- X% date > foofile_c
- Xi-search: le
- X
- X
- XAnother useful feature of the editor is command and filename
- Xcompletion.
- X
- X% compTAB
- X% compress _
- X
- X% ls /nicTAB
- X% ls /nicecolors _
- X
- X% ls /usr/prTAB
- X% ls /usr/princeton/_
- X
- X% ls -l =comTAB
- X% ls -l =compress _
- X
- X
- XIf the completion is ambiguous, the editor will beep. You
- Xcan list possible completions by pressing ^D:
- X
- X% ls /vmuTAB -beep-
- X% ls /vmunix_
- X% ls /vmunix^D
- Xvmunix vmunix.old
- Xvmunix.new.kernelmap.old vmunix.org
- X
- X
- XOr, you could just set the AUTOLIST option:
- X
- X% setopt autolist
- X% ls /vmuTAB -beep-
- Xvmunix vmunix.old
- Xvmunix.new.kernelmap.old vmunix.org
- X% ls /vmunix_
- X
- X
- XAnother option you could set is RECEXACT, which causes exact
- Xmatches to be accepted, even if there are other possible
- Xcompletions:
- X
- X% setopt recexact
- X% ls /vmuTAB -beep-
- Xvmunix vmunix.old
- Xvmunix.new.kernelmap.old vmunix.org
- X% ls /vmunix_TAB
- X% ls /vmunix _
- X
- X
- XThe fignore variable lists suffixes of files to ignore
- X
- X
- X
- X
- X
- X - 24 -
- Xduring completion.
- X
- X% ls fooTAB -beep-
- Xfoofile.c foofile.o
- X% fignore=( .o \~ .bak .junk )
- X% ls fooTAB
- X% ls foofile.c _
- X
- X
- XSince foofile.o has a suffix that is in the fignore list, it
- Xwas not considered a possible completion of foo.
- X
- XUsername completion is also supported:
- X
- X% ls ~pfalTAB
- X% ls ~pfalstad/_
- X
- X
- Xand parameter name completion:
- X
- X% echo $ORGTAB
- X% echo $ORGANIZATION _
- X
- X
- Xand hostname completion, if you give the shell a list of
- Xhosts to complete:
- X
- X% hosts=( phoenix.princeton.edu uunet.uu.net nic.ddn.mil
- X> diskfarm.princeton.edu gnu.ai.mit.edu
- X> eniac.seas.upenn.edu )
- X% telnet diskTAB
- X% telnet diskfarm.princeton.edu _
- X
- X% ftp uuTAB
- X% ftp uunet.uu.net _
- X
- X% mail subbarao@phTAB
- X% mail subbarao@phoenix.princeton.edu _
- X
- X
- Xand option completion:
- X
- X% setopt noclTAB
- X% setopt noclobber _
- X
- X
- Xand binding completion:
- X
- X% bindkey '^X^X' puTAB
- X% bindkey '^X^X' push-line _
- X
- X
- X
- XThe compctl command is used to control how completion works.
- XFor example, to specify that certain commands show take com-
- Xmands as arguments, you use compctl -c:
- X
- X% compctl -c man nohup
- X% man uptTAB
- X% man uptime _
- X
- X
- X
- X
- X
- X - 25 -
- XTo specify that a command should complete filenames, you
- Xshould use compctl -f. This is the default. It can be com-
- Xbined with -c, as well.
- X
- X% compctl -cf echo
- X% echo uptTAB
- X% echo uptime _
- X
- X% echo foTAB
- X% echo foo.c
- X
- X
- XSimilarly, use -h to specify hostnames, -o to specify
- Xoptions, -v to specify variables, and -b to specify bind-
- Xings.
- X
- X% compctl -h rlogin
- X% compctl -hfc rsh
- X% compctl -b bindkey
- X
- X
- XYou can also use -k to specify a custom list of keywords to
- Xuse in completion.
- X
- X% ftphosts=(ftp.uu.net wuarchive.wustl.edu)
- X% compctl -k ftphosts ftp
- X% ftp wuTAB
- X% ftp wuarchive.wustl.edu _
- X
- X% friends=(cpirazzi subbarao sukthnkr)
- X% compctl -k friends mail finger su
- X% finger cpTAB
- X% finger cpirazzi _
- X
- X
- X
- XIn addition to completion, TAB performs expansion if possi-
- Xble.
- X
- X% ls *.cTAB
- X% ls foofile.c fortune.c rnd.c strfile.c unstr.c_
- X
- X
- XFor example, suppose you have a bunch of weird files in an
- Ximportant directory:
- X
- X% ls
- X * * * ; & % $??foo dspfok foo.c
- X !"foo"! ` \ ` foo rrr
- X
- X
- XYou want to remove them, but you don't want to damage foo.c.
- XHere is one way to do this:
- X
- X% rm *TAB
- X% rm \ \ \*\ \*\ \*\ \ \ \!\"foo\"\! \;\ \&\ %\ \$'
- X'foo \`\ \\\ \` dspfok foo foo.c rrr_
- X
- X
- XWhen you expand *, zsh inserts the names of all the files
- X
- X
- X
- X
- X
- X - 26 -
- Xinto the editing buffer, with proper shell quoting. Now,
- Xjust move back and remove foo.c from the buffer:
- X
- X% rm \ \ \*\ \*\ \*\ \ \ \!\"foo\"\! \;\ \&\ %\ \$'
- X'foo \`\ \\\ \` dspfok foo _rr
- X
- X
- Xand press return. Everything except foo.c will be deleted
- Xfrom the directory.
- X
- XHere's another trick; let's say you have typed this command
- Xin:
- X
- X% gcc -o x.out foob.c -g -Wpointer-arith -Wtrigraphs_
- X
- X
- Xand you forget which library you want. You need to escape
- Xout for a minute and check by typing ls /usr/lib, or some
- Xother such command; but you don't want to retype the whole
- Xcommand again, and you can't press return now because the
- Xcurrent command is incomplete. In zsh, you can put the line
- Xon the buffer stack, using ESC-Q, and type some other com-
- Xmands. The next time a prompt is printed, the gcc line will
- Xbe popped off the stack and put in the editing buffer
- Xautomatically; you can then enter the proper library name
- Xand press return (or, ESC-Q again and look for some other
- Xlibraries whose names you forgot).
- X
- XA similar situation: what if you forget the option to gcc
- Xthat finds bugs using AI techniques? You could either use
- XESC-Q again, and type man gcc, or you could press ESC-H,
- Xwhich essentially does the same thing; it puts the current
- Xline on the buffer stack, and executes the command run-help
- Xgcc, where run-help is an alias for man.
- X
- XAnother interesting command is ESC-A. This executes the
- Xcurrent line, but retains it in the buffer, so that it
- Xappears again when the next prompt is printed. Also, the
- Xcursor stays in the same place. This is useful for execut-
- Xing a series of similar commands:
- X
- X% cc grok.c -g -lc -lgl -lsun -lmalloc -Bstatic -o b.out
- X% cc fubar.c -g -lc -lgl -lsun -lmalloc -Bstatic -o b.out
- X% cc fooble.c -g -lc -lgl -lsun -lmalloc -Bstatic -o b.out
- X
- X
- X
- XThe ESC-' command is useful for managing the shell's quoting
- Xconventions. Let's say you want to print this string:
- X
- Xdon't do that; type 'rm -rf \*', with a \ before the *.
- X
- X
- XAll that is necessary is to type it into the editing buffer:
- X
- X% don't do that; type 'rm -rf \*', with a \ before the *.
- X
- X
- Xpress ESC-' (escape-quote):
- X
- X
- X
- X
- X
- X
- X - 27 -
- X
- X% 'don'\''t do that; type '\''rm -rf \*'\'', with a \ before the *.'
- X
- X
- Xthen move to the beginning and add the echo command.
- X
- X% echo 'don'\''t do that; type '\''rm -rf \*'\'', with a \ before the *.'
- Xdon't do that; type 'rm -rf \*', with a \ before the *.
- X
- X
- XLet's say you want to create an alias to do this echo com-
- Xmand. This can be done by recalling the line with ^P and
- Xpressing ESC-' again:
- X
- X% 'echo '\''don'\''\'\'''\''t do that; type '\''\'\'''\''rm -rf
- X\*'\''\'\'''\'', with a \ before the *.'\'''
- X
- X
- Xand then move to the beginning and add the command to create
- Xan alias.
- X
- X% alias zoof='echo '\''don'\''\'\'''\''t do that; type '\''\'\'''\''rm
- X-rf \*'\''\'\'''\'', with a \ before the *.'\'''
- X% zoof
- Xdon't do that; type 'rm -rf \*', with a \ before the *.
- X
- X
- X
- XAnother interesting option is MENUCOMPLETE. This affects
- Xthe way TAB works. Let's look at the /vmunix example again:
- X
- X% setopt menucomplete
- X% ls /vmuTAB
- X% ls /vmunixTAB
- X% ls /vmunix.new.kernelmap.oldTAB
- X% ls /vmunix.old_
- X
- X
- XEach time you press TAB, it displays the next possible com-
- Xpletion. In this way, you can cycle through the possible
- Xcompletions until you find the one you want.
- X
- XThe AUTOMENU option makes a nice compromise between this
- Xmethod of completion and the regular method. If you set
- Xthis option, pressing the TAB key repeatedly after an ambi-
- Xguous completion will cycle through the possible comple-
- Xtions.
- X
- XBindings
- X
- XEach of the above editor commands was actually a function
- Xbound by default to a certain key. The real names of the
- Xcommands are:
- X
- Xexpand-or-complete TAB
- Xpush-line ESC-Q
- Xrun-help ESC-H
- Xaccept-and-hold ESC-A
- Xquote-line ESC-'
- X
- X
- X
- X
- X
- X
- X - 28 -
- XThese bindings are arbitrary; you could change them if you
- Xwant. For example, to bind accept-line to ^Z:
- X
- X% bindkey '^Z' accept-line
- X
- X
- XAnother idea would be to bind the delete key to delete-char;
- Xthis might be convenient if you use ^H for backspace.
- X
- X% bindkey '^?' delete-char
- X
- X
- XOr, you could bind ^X^H to run-help:
- X
- X% bindkey '^X^H' run-help
- X
- X
- XOther examples:
- X
- X% bindkey '^X^Z' universal-argument
- X% bindkey ' ' magic-space
- X% bindkey -s '^T' 'uptime
- X> '
- X
- X
- Xuniversal-argument multiplies the next command by 4. Thus
- X^X^Z^W might delete the last four words on the line. If you
- Xbind space to magic-space, then csh-style history expansion
- Xis done on the line whenever you press the space bar.
- X
- XThe -s flag to bindkey specifies that you are binding the
- Xkey to a string, not a command. Thus bindkey -s '^T'
- X'uptime\n' lets you VMS lovers get the load average whenever
- Xyou press ^T.
- X
- XIf you have a NeXT keyboard, the one with the | and \ keys
- Xvery inconveniently placed, the following bindings may come
- Xin handy:
- X
- X% bindkey -s '\e/' '\\'
- X% bindkey -s '\e=' '|'
- X
- X
- XNow you can type ALT-/ to get a backslash, and ALT-= to get
- Xa vertical bar. This only works inside zsh, of course;
- Xbindkey has no effect on the key mappings inside talk or
- Xmail, etc.
- X
- XAnother use of the editor is to edit the value of variables.
- XFor example, an easy way to change your path is to use the
- Xvared command:
- X
- X% vared PATH
- X> /u/pfalstad/scr:/u/pfalstad/bin/sun4:/u/maruchck/scr:/u/subbarao/bin:/u/maruc
- Xhck/bin:/u/subbarao/scripts:/usr/princeton/bin:/usr/ucb:/usr/bin:/bin:/usr/host
- Xs:/usr/princeton/bin/X11:/./usr/lang:/./usr/etc:/./etc
- X
- X
- XYou can now edit the path. When you press return, the con-
- Xtents of the edit buffer will be assigned to PATH.
- X
- X
- X
- X
- X
- X - 29 -
- XParameter Substitution
- X
- XIn zsh, parameters are set like this:
- X
- X% foo=bar
- X% echo $foo
- Xbar
- X
- X
- XSpaces before or after the = are frowned upon:
- X
- X% foo = bar
- Xzsh: command not found: foo
- X
- X
- XAlso, set doesn't work for setting parameters:
- X
- X% set foo=bar
- X% set foo = bar
- X% echo $foo
- X
- X%
- X
- X
- XNote that no error message was printed. This is because
- Xboth of these commands were perfectly valid; the set builtin
- Xassigns its arguments to the positional parameters ($1, $2,
- Xetc.).
- X
- X% set foo=bar
- X% echo $1
- Xfoo=bar
- X% set foo = bar
- X% echo $3 $2
- Xbar =
- X
- X
- XIf you're really intent on using the csh syntax, define a
- Xfunction like this:
- X
- X% set () {
- X> eval "$1$2$3"
- X> }
- X% set foo = bar
- X% set fuu=brrr
- X% echo $foo $fuu
- Xbar brrr
- X
- X
- XBut then, of course you can't use the form of set with
- Xoptions, like set -F (which turns off filename generation).
- XAlso, the set command by itself won't list all the parame-
- Xters like it should. To get around that you need a case
- Xstatement:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 30 -
- X
- X% set () {
- X> case $1 in
- X> -*|+*|'') builtin set $* ;;
- X> *) eval "$1$2$3" ;;
- X> esac
- X> }
- X
- X
- XFor the most part, this should make csh users happy.
- X
- XThe following sh-style operators are supported in zsh:
- X
- X% unset null
- X% echo ${foo-xxx}
- Xbar
- X% echo ${null-xxx}
- Xxxx
- X% unset null
- X% echo ${null=xxx}
- Xxxx
- X% echo $null
- Xxxx
- X% echo ${foo=xxx}
- Xbar
- X% echo $foo
- Xbar
- X% unset null
- X% echo ${null+set}
- X
- X% echo ${foo+set}
- Xset
- X
- X
- XAlso, csh-style : modifiers may be appended to a parameter
- Xsubstitution.
- X
- X% echo $PWD
- X/home/learning/pf/zsh/zsh2.00/src
- X% echo $PWD:h
- X/home/learning/pf/zsh/zsh2.00
- X% echo $PWD:h:h
- X/home/learning/pf/zsh
- X% echo $PWD:t
- Xsrc
- X% name=foo.c
- X% echo $name
- Xfoo.c
- X% echo $name:r
- Xfoo
- X% echo $name:e
- Xc
- X
- X
- XThe equivalent constructs in ksh (which are also supported
- Xin zsh) are a bit more general and easier to remember. When
- Xthe shell expands ${foo#pat}, it checks to see if pat
- Xmatches a substring at the beginning of the value of foo.
- XIf so, it removes that portion of foo, using the shortest
- Xpossible match. With ${foo##pat}, the longest possible
- X
- X
- X
- X
- X
- X - 31 -
- Xmatch is removed. ${foo%pat} and ${foo%%pat} remove the
- Xmatch from the end. Here are the ksh equivalents of the :
- Xmodifiers:
- X
- X% echo ${PWD%/*}
- X/home/learning/pf/zsh/zsh2.00
- X% echo ${PWD%/*/*}
- X/home/learning/pf/zsh
- X% echo ${PWD##*/}
- Xsrc
- X% echo ${name%.*}
- Xfoo
- X% echo ${name#*.}
- Xc
- X
- X
- Xzsh also has upper/lowercase modifiers:
- X
- X% xx=Test
- X% echo $xx:u
- XTEST
- X% echo $xx:l
- Xtest
- X
- X
- Xand a substitution modifier:
- X
- X% echo $name:s/foo/bar/
- Xbar.c
- X% ls
- Xfoo.c foo.h foo.o foo.pro
- X% for i in foo.*; mv $i $i:s/foo/bar/
- X% ls
- Xbar.c bar.h bar.o bar.pro
- X
- X
- XOne possible source of confusion is the fact that in zsh,
- Xthe result of parameter substitution is not split into
- Xwords. Thus, this will not work:
- X
- X% srcs='glob.c exec.c init.c'
- X% ls $srcs
- Xglob.c exec.c init.c not found
- X
- X
- XThis is considered a feature, not a bug. If splitting were
- Xdone by default, as it is in most other shells, functions
- Xlike this would not work properly:
- X
- X$ ll () { ls -F $* }
- X$ ll 'fuu bar'
- Xfuu not found
- Xbar not found
- X
- X% ll 'fuu bar'
- Xfuu bar not found
- X
- X
- XOf course, a hackish workaround is available in sh (and
- Xzsh):
- X
- X
- X
- X
- X
- X - 32 -
- X
- X% setopt shwordsplit
- X% ll () { ls -F "$@" }
- X% ll 'fuu bar'
- Xfuu bar not found
- X
- X
- XIf you like the sh behaviour, zsh can accomodate you:
- X
- X% ls ${=srcs}
- Xexec.c glob.c init.c
- X% setopt shwordsplit
- X% ls $srcs
- Xexec.c glob.c init.c
- X
- X
- XAnother way to get the $srcs trick to work is to use an
- Xarray:
- X
- X% unset srcs
- X% srcs=( glob.c exec.c init.c )
- X% ls $srcs
- Xexec.c glob.c init.c
- X
- X
- Xor an alias:
- X
- X% alias -g SRCS='exec.c glob.c init.c'
- X% ls SRCS
- Xexec.c glob.c init.c
- X
- X
- XAnother option that modifies parameter expansion is RCEX-
- XPANDPARAM:
- X
- X% echo foo/$srcs
- Xfoo/glob.c exec.c init.c
- X% setopt rcexpandparam
- X% echo foo/$srcs
- Xfoo/glob.c foo/exec.c foo/init.c
- X% echo foo/${^srcs}
- Xfoo/glob.c foo/exec.c foo/init.c
- X% echo foo/$^srcs
- Xfoo/glob.c foo/exec.c foo/init.c
- X
- X
- X
- XShell Parameters
- X
- XThe shell has many predefined parameters that may be
- Xaccessed. Here are some examples:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 33 -
- X
- X% sleep 10 &
- X[1] 3820
- X% echo $!
- X3820
- X% set a b c
- X% echo $#
- X3
- X% echo $ARGC
- X3
- X% ( exit 20 ) ; echo $?
- X20
- X% false; echo $status
- X1
- X
- X
- X($? and $status are equivalent.)
- X
- X% echo $HOST $HOSTTYPE
- Xdendrite sun4
- X% echo $UID $GID
- X701 60
- X% cd /tmp
- X% cd /home
- X% echo $PWD $OLDPWD
- X/home /tmp
- X% ls $OLDPWD/.getwd
- X/tmp/.getwd
- X
- X
- X~+ and ~- are short for $PWD and $OLDPWD, respectively.
- X
- X% ls ~-/.getwd
- X/tmp/.getwd
- X% ls -d ~+/learning
- X/home/learning
- X% echo $RANDOM
- X4880
- X% echo $RANDOM
- X11785
- X% echo $RANDOM
- X2062
- X% echo $TTY
- X/dev/ttyp4
- X% echo $VERSION
- Xzsh v2.00.03
- X% echo $USERNAME
- Xpf
- X
- X
- X
- XThe cdpath variable sets the search path for the cd command.
- XIf you do not specify . somewhere in the path, it is assumed
- Xto be the first component.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 34 -
- X
- X% cdpath=( /usr ~ ~/zsh )
- X% ls /usr
- X5bin dict lang net sccs sys
- X5include etc lector nserve services tmp
- X5lib export lib oed share ucb
- Xadm games local old skel ucbinclude
- Xbin geac lost+found openwin spool ucblib
- Xboot hosts macsyma_417 pat src xpg2bin
- Xdemo include man princeton stand xpg2include
- Xdiag kvm mdec pub swap xpg2lib
- X% cd spool
- X/usr/spool
- X% cd bin
- X/usr/bin
- X% cd func
- X~/func
- X% cd
- X% cd pub
- X% pwd
- X/u/pfalstad/pub
- X% ls -d /usr/pub
- X/usr/pub
- X
- X
- XPATH and path both set the search path for commands. These
- Xtwo variables are equivalent, except that one is a string
- Xand one is an array. If the user modifies PATH, the shell
- Xchanges path as well, and vice versa.
- X
- X% PATH=/bin:/usr/bin:/tmp:.
- X% echo $path
- X/bin /usr/bin /tmp .
- X% path=( /usr/bin . /usr/local/bin /usr/ucb )
- X% echo $PATH
- X/usr/bin:.:/usr/local/bin:/usr/ucb
- X
- X
- XThe same is true of CDPATH and cdpath:
- X
- X% echo $CDPATH
- X/usr:/u/pfalstad:/u/pfalstad/zsh
- X% CDPATH=/u/subbarao:/usr/src:/tmp
- X% echo $cdpath
- X/u/subbarao /usr/src /tmp
- X
- X
- XIn general, parameters with names in all lowercase are
- Xarrays; assignments to them take the form:
- X
- Xname=( elem ... )
- X
- X
- XParameters with names in all uppercase are strings. If
- Xthere is both an array and a string version of the same
- Xparameter, the string version is a colon-separated list,
- Xlike PATH.
- X
- XHISTFILE is the name of the history file, where the history
- Xis saved when a shell exits.
- X
- X
- X
- X
- X
- X - 35 -
- X
- X% zsh
- Xphoenix% HISTFILE=/tmp/history
- Xphoenix% SAVEHIST=20
- Xphoenix% echo foo
- Xfoo
- Xphoenix% date
- XFri May 24 05:39:35 EDT 1991
- Xphoenix% uptime
- X 5:39am up 4 days, 20:02, 40 users, load average: 2.30, 2.20, 2.00
- Xphoenix% exit
- X% cat /tmp/history
- XHISTFILE=/tmp/history
- XSAVEHIST=20
- Xecho foo
- Xdate
- Xuptime
- Xexit
- X% HISTSIZE=3
- X% history
- X 28 rm /tmp/history
- X 29 HISTSIZE=3
- X 30 history
- X
- X
- X
- XIn zsh, if you say
- X
- X% >file
- X
- X
- Xthe command cat is normally assumed:
- X
- X% >file
- Xfoo!
- X^D
- X% cat file
- Xfoo!
- X
- X
- XThus, you can view a file simply by typing:
- X
- X% <file
- Xfoo!
- X
- X
- XHowever, this is not csh or sh compatible. To correct this,
- Xchange the value of the parameter NULLCMD, which is cat by
- Xdefault.
- X
- X% NULLCMD=:
- X% >file
- X% ls -l file
- X-rw-r--r-- 1 pfalstad 0 May 24 05:41 file
- X
- X
- XIf NULLCMD is unset, the shell reports an error if no com-
- Xmand is specified (like csh).
- X
- X
- X
- X
- X
- X
- X
- X - 36 -
- X
- X% unset NULLCMD
- X% >file
- Xzsh: redirection with no command
- X
- X
- XActually, READNULLCMD is used whenever you have a null com-
- Xmand reading input from a single file. Thus, you can set
- XREADNULLCMD to more or less rather than cat. Also, if you
- Xset NULLCMD to : for sh compatibility, you can still read
- Xfiles with < file if you leave READNULLCMD set to more.
- X
- XPrompting
- X
- XThe default prompt for zsh is:
- X
- Xphoenix% echo $PROMPT
- X%m%#
- X
- X
- XThe %m stands for the short form of the current hostname,
- Xand the %# stands for a % or a #, depending on whether the
- Xshell is running as root or not. zsh supports many other
- Xcontrol sequences in the PROMPT variable.
- X
- X% PROMPT='%/> '
- X/u/pfalstad/etc/TeX/zsh>
- X
- X% PROMPT='%~> '
- X~/etc/TeX/zsh>
- X
- X% PROMPT='%h %~> '
- X6 ~/etc/TeX/zsh>
- X
- X
- X%h represents the number of current history event.
- X
- X% PROMPT='%h %~ %M> '
- X10 ~/etc/TeX/zsh apple-gunkies.gnu.ai.mit.edu>
- X
- X% PROMPT='%h %~ %m> '
- X11 ~/etc/TeX/zsh apple-gunkies>
- X
- X% PROMPT='%h %t> '
- X12 6:11am>
- X
- X% PROMPT='%n %w tty%l>'
- Xpfalstad Fri 24 ttyp0>
- X
- X
- XAlso available is the RPROMPT parameter. If this is set,
- Xthe shell puts a prompt on the right side of the screen.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 37 -
- X
- X% RPROMPT='%t'
- X% 6:14am
- X
- X% RPROMPT='%~'
- X% ~/etc/TeX/zsh
- X
- X% PROMPT='%l %T %m[%h] ' RPROMPT=' %~'
- Xp0 6:15 phoenix[5] ~/etc/TeX/zsh
- X
- X
- XThese special escape sequences can also be used with the -P
- Xoption to print:
- X
- X% print -P %h tty%l
- X15 ttyp1
- X
- X
- X
- XThe POSTEDIT parameter is printed whenever the editor exits.
- XThis can be useful for termcap tricks. To highlight the
- Xprompt and command line while leaving command output
- Xunhighlighted, try this:
- X
- X% POSTEDIT=`echotc se`
- X% PROMPT='%S%% '
- X
- X
- X
- XLogin/logout watching
- X
- XYou can specify login or logout events to monitor by setting
- Xthe watch variable. Normally, this is done by specifying a
- Xlist of usernames.
- X
- X% watch=( pfalstad subbarao sukthnkr egsirer )
- X
- X
- XThe log command reports all people logged in that you are
- Xwatching for.
- X
- X% log
- Xpfalstad has logged on p0 from mickey.
- Xpfalstad has logged on p5 from mickey.
- X% ...
- Xsubbarao has logged on p8 from phoenix.
- X% ...
- Xsubbarao has logged off p8 from phoenix.
- X% ...
- Xsukthnkr has logged on p8 from dew.
- X% ...
- Xsukthnkr has logged off p8 from dew.
- X
- X
- XIf you specify hostnames with an @ prepended, the shell will
- Xwatch for all users logging in from the specified host.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 38 -
- X
- X% watch=( @mickey @phoenix )
- X% log
- Xdjthongs has logged on q2 from phoenix.
- Xpfalstad has logged on p0 from mickey.
- Xpfalstad has logged on p5 from mickey.
- X
- X
- XIf you give a tty name with a % prepended, the shell will
- Xwatch for all users logging in on that tty.
- X
- X% watch=( %ttyp0 %console )
- X% log
- Xroot has logged on console from .
- Xpfalstad has logged on p0 from mickey.
- X
- X
- XThe format of the reports may also be changed.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 39 -
- X
- X% watch=( pfalstad gettes eps djthongs jcorr bdavis )
- X% log
- Xjcorr has logged on tf from 128.112.176.3:0.
- Xjcorr has logged on r0 from 128.112.176.3:0.
- Xgettes has logged on p4 from yo:0.0.
- Xdjthongs has logged on pe from grumpy:0.0.
- Xdjthongs has logged on q2 from phoenix.
- Xbdavis has logged on qd from BRUNO.
- Xeps has logged on p3 from csx30:0.0.
- Xpfalstad has logged on p0 from mickey.
- Xpfalstad has logged on p5 from mickey.
- X% WATCHFMT='%n on tty%l from %M'
- X% log
- Xjcorr on ttytf from 128.112.176.3:0.
- Xjcorr on ttyr0 from 128.112.176.3:0.
- Xgettes on ttyp4 from yo:0.0
- Xdjthongs on ttype from grumpy:0.0
- Xdjthongs on ttyq2 from phoenix.Princeto
- Xbdavis on ttyqd from BRUNO.pppl.gov
- Xeps on ttyp3 from csx30:0.0
- Xpfalstad on ttyp0 from mickey.Princeton
- Xpfalstad on ttyp5 from mickey.Princeton
- X% WATCHFMT='%n fm %m'
- X% log
- Xjcorr fm 128.112.176.3:0
- Xjcorr fm 128.112.176.3:0
- Xgettes fm yo:0.0
- Xdjthongs fm grumpy:0.0
- Xdjthongs fm phoenix
- Xbdavis fm BRUNO
- Xeps fm csx30:0.0
- Xpfalstad fm mickey
- Xpfalstad fm mickey
- X% WATCHFMT='%n %a at %t %w.'
- X% log
- Xjcorr logged on at 3:15pm Mon 20.
- Xjcorr logged on at 3:16pm Wed 22.
- Xgettes logged on at 6:54pm Wed 22.
- Xdjthongs logged on at 7:19am Thu 23.
- Xdjthongs logged on at 7:20am Thu 23.
- Xbdavis logged on at 12:40pm Thu 23.
- Xeps logged on at 4:19pm Thu 23.
- Xpfalstad logged on at 3:39am Fri 24.
- Xpfalstad logged on at 3:42am Fri 24.
- X
- X
- XIf you have a .friends file in your home directory, a con-
- Xvenient way to make zsh watch for all your friends is to do
- Xthis:
- X
- X% watch=( $(< ~/.friends) )
- X% echo $watch
- Xsubbarao maruchck root sukthnkr ...
- X
- X
- XIf watch is set to all, then all users logging in or out
- Xwill be reported.
- X
- X
- X
- X
- X
- X
- X
- X - 40 -
- XOptions
- X
- XSome options have already been mentioned; here are a few
- Xmore:
- X
- X% cd /
- X% setopt autocd
- X% bin
- X% pwd
- X/bin
- X% ../etc
- X% pwd
- X/etc
- X
- X
- XUsing the AUTOCD option, you can simply type the name of a
- Xdirectory, and it will become the current directory.
- X
- X% setopt cdablevars
- X% foo=/tmp
- X% cd foo
- X/tmp
- X
- X
- XWith CDABLEVARS, if the argument to cd is the name of a
- Xparameter whose value is a valid directory, it will become
- Xthe current directory.
- X
- XCORRECT turns on spelling correction for commands, and the
- XCORRECTALL option turns on spelling correction for all argu-
- Xments.
- X
- X% setopt correct
- X% sl
- Xzsh: correct `sl' to `ls' [nyae]? y
- X% setopt correctall
- X% ls x.v11r4
- Xzsh: correct `x.v11r4' to `X.V11R4' [nyae]? n
- X/usr/princton/src/x.v11r4 not found
- X% ls /etc/paswd
- Xzsh: correct to `/etc/paswd' to `/etc/passwd' [nyae]? y
- X/etc/passwd
- X
- X
- XIf you press y when the shell asks you if you want to
- Xcorrect a word, it will be corrected. If you press n, it
- Xwill be left alone. Pressing a aborts the command, and
- Xpressing e brings the line up for editing again, in case you
- Xagree the word is spelled wrong but you don't like the
- Xcorrection.
- X
- XNormally, a quoted expression may contain a newline:
- X
- X% echo '
- X> foo
- X> '
- X
- Xfoo
- X
- X%
- X
- X
- X
- X
- X
- X - 41 -
- XWith CSHJUNKIEQUOTES set, this is illegal, as it is in csh.
- X
- X% setopt cshjunkiequotes
- X% ls 'foo
- Xzsh: unmatched '
- X
- X
- XGLOBDOTS lets files beginning with a . be matched without
- Xexplicitly specifying the dot.
- X
- X% ls -d *x*
- XMailboxes
- X% setopt globdots
- X% ls -d *x*
- X.exrc .pnewsexpert .xserverrc
- X.mushexpert .xinitrc Mailboxes
- X
- X
- XHISTIGNOREDUPS prevents the current line from being saved in
- Xthe history if it is the same as the previous one; HISTIG-
- XNORESPACE prevents the current line from being saved if it
- Xbegins with a space.
- X
- X% PROMPT='%h> '
- X39> setopt histignoredups
- X40> echo foo
- Xfoo
- X41> echo foo
- Xfoo
- X41> echo foo
- Xfoo
- X41> echo bar
- Xbar
- X42> setopt histignorespace
- X43> echo foo
- Xfoo
- X43> echo fubar
- Xfubar
- X43> echo fubar
- Xfubar
- X
- X
- XIGNOREBRACES turns off csh-style brace expansion.
- X
- X% echo x{y{z,a},{b,c}d}e
- Xxyze xyae xbde xcde
- X% setopt ignorebraces
- X% echo x{y{z,a},{b,c}d}e
- Xx{y{z,a},{b,c}d}e
- X
- X
- XIGNOREEOF forces the user to type exit or logout, instead of
- Xjust pressing ^D.
- X
- X% setopt ignoreeof
- X% ^D
- Xzsh: use 'exit' to exit.
- X
- X
- XINTERACTIVECOMMENTS turns on interactive comments; comments
- X
- X
- X
- X
- X
- X - 42 -
- Xbegin with a #.
- X
- X% setopt interactivecomments
- X% date # this is a comment
- XFri May 24 06:54:14 EDT 1991
- X
- X
- XNOCLOBBER prevents you from accidentally overwriting an
- Xexisting file.
- X
- X% setopt noclobber
- X% cat /dev/null >~/.zshrc
- Xzsh: file exists: /u/pfalstad/.zshrc
- X
- X
- XIf you really do want to clobber a file, you can use the >!
- Xoperator. To make things easier in this case, the > is
- Xstored in the history list as a >!:
- X
- X% cat /dev/null >! ~/.zshrc
- X% cat /etc/motd > ~/.zshrc
- Xzsh: file exists: /u/pfalstad/.zshrc
- X% !!
- Xcat /etc/motd >! ~/.zshrc
- X% ...
- X
- X
- XRCQUOTES lets you use a more elegant method for including
- Xsingle quotes in a singly quoted string:
- X
- X% echo '"don'\''t do that."'
- X"don't do that."
- X% echo '"don''t do that."'
- X"dont do that."
- X% setopt rcquotes
- X% echo '"don''t do that."'
- X"don't do that."
- X
- X
- XFinally, SUNKEYBOARDHACK wins the award for the strangest
- Xoption. If a line ends with `, and there are an odd number
- Xof them on the line, the shell will ignore the trailing `.
- XThis is provided for keyboards whose RETURN key is too
- Xsmall, and too close to the ` key.
- X
- X% setopt sunkeyboardhack
- X% date`
- XFri May 24 06:55:38 EDT 1991
- X
- X
- X
- XClosing Comments
- X
- XI would be happy to receive mail if anyone has any tricks or
- Xideas to add to this document, or if there are some points
- Xthat could be made clearer or covered more thoroughly.
- XPlease notify me of any errors in this document.
- X
- X
- X
- X
- X
- X
- SHAR_EOF
- echo 'File zsh2.2/doc/intro.txt is complete' &&
- chmod 0644 zsh2.2/doc/intro.txt ||
- echo 'restore of zsh2.2/doc/intro.txt failed'
- Wc_c="`wc -c < 'zsh2.2/doc/intro.txt'`"
- test 58603 -eq "$Wc_c" ||
- echo 'zsh2.2/doc/intro.txt: original size 58603, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/dots/zlogin ==============
- if test ! -d 'zsh2.2/dots'; then
- echo 'x - creating directory zsh2.2/dots'
- mkdir 'zsh2.2/dots'
- fi
- if test -f 'zsh2.2/dots/zlogin' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/dots/zlogin (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/dots/zlogin (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/dots/zlogin' &&
- Xclear
- Xcd
- Xstty dec new cr0 -tabs
- Xttyctl -f # freeze the terminal modes... can't change without a ttyctl -u
- Xumask 022
- Xexport MAIL=/usr/spool/mail/$USER
- XMAILCHECK=60
- Xmesg y
- Xuptime
- Xfortune
- Xlog
- Xfrom 2>/dev/null
- Xcat notes
- Xunlimit
- Xlimit core 0
- Xmsgs -fp
- SHAR_EOF
- chmod 0644 zsh2.2/dots/zlogin ||
- echo 'restore of zsh2.2/dots/zlogin failed'
- Wc_c="`wc -c < 'zsh2.2/dots/zlogin'`"
- test 247 -eq "$Wc_c" ||
- echo 'zsh2.2/dots/zlogin: original size 247, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/dots/zshrc ==============
- if test -f 'zsh2.2/dots/zshrc' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/dots/zshrc (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/dots/zshrc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/dots/zshrc' &&
- X#
- X# my rc file for zsh 2.2
- X# all this runs in interactive shells only
- X#
- X
- X# search path for the cd command
- Xcdpath=(. ~ ~/src/cs320 ~/src)
- X
- X# where to look for function definitions
- X# fpath=(~/func)
- X
- X# useful directory
- Xcsrc=/usr/princeton/common/src
- X
- X# use hard limits, except for a smaller stack and no core dumps
- Xunlimit
- Xlimit stack 8192
- Xlimit core 0
- Xlimit -s
- X
- Xumask 022
- X
- X# define some aliases
- Xalias a=alias
- Xa a.out=./a.out sendmail=/usr/lib/sendmail c=cp 0=vi 09='vi -t' 00=r
- Xa d=dirs en='enscript -2rGh' fm='finger -m' grep=egrep h=history
- Xa hinfo='host -t hinfo' j=jobs l='ls -AF' lock='lock -p -60000'
- Xa lsd='ls -d */' m=make mm=less
- Xa nrable='ls -AFltrd *(^R)' sz='ls -l | sort -n +3 | tail -20'
- Xa sn='sed -n' nw='l -ltr | tail' pd=pushd pop=popd mroe=more
- Xa rable='ls -AFltrd *(R)' strings='strings -' t=cat
- Xa v=mv where='hostname; echo >/dev/null' k9='kill -9' whoami='echo root'
- Xa find='noglob find' bindkey='noglob bindkey' dh='dirs -v'
- Xa mv='nocorrect mv' z=suspend
- X
- X# global aliases
- Xa -g 'GF'='| fgrep -f ~/.friends' G='| grep' M='| less' cex='/u/pup/centrex'
- X
- X# setenv for csh junkies (including tset)
- Xsetenv() { export $1=$2 }
- X
- Xmanpath=(/usr/man /usr/princeton/man /u/cad/man /usr/lang/man)
- Xexport MANPATH
- X
- X# filename completion suffixes to ignore
- Xfignore=(.o .pro .old)
- X
- X# hosts to use for completion
- Xhosts=(uunet.uu.net `hostname` wuarchive.wustl.edu quiche.cs.mcgill.ca)
- X
- XPROMPT='%l %T %m[%h] '
- X
- X# prompt on the right side of the screen
- XRPROMPT=' %~'
- X
- X# some environment variables
- Xexport MAILCALL='NEW MAIL! '
- Xexport YOUSAID='In %C you wrote:'
- Xexport ATTRIBUTION='%f wrote:'
- X
- X# functions to autoload
- X# autoload cx acx mere yu yp randline proto namedir ilogin
- X
- XMAILCHECK=30
- XHISTSIZE=600
- XDIRSTACKSIZE=50
- X
- X# lots of options
- Xsetopt notify globdots correct pushdtohome cdablevars autolist \
- X sunkeyboardhack correctall autocd recexact longlistjobs mailwarning \
- X autoresume histignoredups pushdsilent noclobber \
- X autopushd pushdminus extendedglob rcquotes
- Xunsetopt bgnice
- X
- X# watch for my friends
- Xwatch=($(cat ~/.friends))
- XWATCHFMT='%n %a %l from %m at %t.'
- XLOGCHECK=0
- X
- Xexport LESS=-ainx3
- Xunhash p
- X
- X# some nice bindings
- Xbindkey '^X^Z' universal-argument ' ' magic-space
- Xbindkey '^X^A' vi-find-prev-char-skip
- Xbindkey '^Z' accept-and-hold
- Xbindkey -s '\M-/' \\\\
- Xbindkey -s '\M-=' \|
- SHAR_EOF
- chmod 0644 zsh2.2/dots/zshrc ||
- echo 'restore of zsh2.2/dots/zshrc failed'
- Wc_c="`wc -c < 'zsh2.2/dots/zshrc'`"
- test 2291 -eq "$Wc_c" ||
- echo 'zsh2.2/dots/zshrc: original size 2291, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/dots/zshenv ==============
- if test -f 'zsh2.2/dots/zshenv' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/dots/zshenv (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/dots/zshenv (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/dots/zshenv' &&
- Xpath=(~/scr ~/bin/$HOSTTYPE
- X /usr/princeton/bin /usr/ucb /usr/bin /bin
- X /usr/hosts /usr/princeton/bin/X11 /usr/etc /etc .)
- SHAR_EOF
- chmod 0644 zsh2.2/dots/zshenv ||
- echo 'restore of zsh2.2/dots/zshenv failed'
- Wc_c="`wc -c < 'zsh2.2/dots/zshenv'`"
- test 123 -eq "$Wc_c" ||
- echo 'zsh2.2/dots/zshenv: original size 123, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/acx ==============
- if test ! -d 'zsh2.2/func'; then
- echo 'x - creating directory zsh2.2/func'
- mkdir 'zsh2.2/func'
- fi
- if test -f 'zsh2.2/func/acx' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/acx (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/acx (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/acx' &&
- X#! /bin/sh
- X#
- X# zsh shell function to make its arguments 755
- X# also works as an sh script
- X#
- Xchmod 755 $*
- SHAR_EOF
- chmod 0755 zsh2.2/func/acx ||
- echo 'restore of zsh2.2/func/acx failed'
- Wc_c="`wc -c < 'zsh2.2/func/acx'`"
- test 104 -eq "$Wc_c" ||
- echo 'zsh2.2/func/acx: original size 104, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/cx ==============
- if test -f 'zsh2.2/func/cx' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/cx (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/cx (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/cx' &&
- X#! /bin/sh
- X#
- X# zsh shell function to make its arguments executable
- X# also works as a sh script
- X#
- Xchmod +x $*
- SHAR_EOF
- chmod 0755 zsh2.2/func/cx ||
- echo 'restore of zsh2.2/func/cx failed'
- Wc_c="`wc -c < 'zsh2.2/func/cx'`"
- test 109 -eq "$Wc_c" ||
- echo 'zsh2.2/func/cx: original size 109, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/harden ==============
- if test -f 'zsh2.2/func/harden' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/harden (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/harden (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/harden' &&
- X#! /bin/sh
- X# harden a link (convert it to a singly linked file)
- Xcp $1 $1.foo
- Xrm $1
- Xmv $1.foo $1
- X
- SHAR_EOF
- chmod 0755 zsh2.2/func/harden ||
- echo 'restore of zsh2.2/func/harden failed'
- Wc_c="`wc -c < 'zsh2.2/func/harden'`"
- test 97 -eq "$Wc_c" ||
- echo 'zsh2.2/func/harden: original size 97, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/mere ==============
- if test -f 'zsh2.2/func/mere' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/mere (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/mere (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/mere' &&
- X#! /bin/sh
- X# read a man page in the current directory
- Xnroff -man -Tman $1 | less -s
- SHAR_EOF
- chmod 0755 zsh2.2/func/mere ||
- echo 'restore of zsh2.2/func/mere failed'
- Wc_c="`wc -c < 'zsh2.2/func/mere'`"
- test 84 -eq "$Wc_c" ||
- echo 'zsh2.2/func/mere: original size 84, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/namedir ==============
- if test -f 'zsh2.2/func/namedir' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/namedir (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/namedir (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/namedir' &&
- X# give a name to a directory
- X
- X$1=~+
- X: ~$1
- X
- X# for example, if we say: namedir foo
- X# where the current directory is /usr/princeton/common/src/news/nntp/inews
- X# this will do:
- X#
- X# foo=/usr/princeton/common/src/news/nntp/inews
- X# : ~foo
- X#
- X# The : ~foo just evaluates ~foo, which declares foo as a named directory.
- X# The first time a parameter is used with tilde expansion, it is declared
- X# as the name of a named dir.
- SHAR_EOF
- chmod 0755 zsh2.2/func/namedir ||
- echo 'restore of zsh2.2/func/namedir failed'
- Wc_c="`wc -c < 'zsh2.2/func/namedir'`"
- test 412 -eq "$Wc_c" ||
- echo 'zsh2.2/func/namedir: original size 412, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/proto ==============
- if test -f 'zsh2.2/func/proto' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/proto (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/proto (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/proto' &&
- X#! /bin/sh
- X# generate prototypes, if your style is the same as mine
- Xfor i
- Xdo
- X rm $i:r.pro 2>/dev/null
- X grep -v '[{};:#]' $i | grep '^[A-Za-z]' |
- X grep -v static | sed 's/$/;/' >! $i:r.pro
- Xdone
- SHAR_EOF
- chmod 0755 zsh2.2/func/proto ||
- echo 'restore of zsh2.2/func/proto failed'
- Wc_c="`wc -c < 'zsh2.2/func/proto'`"
- test 194 -eq "$Wc_c" ||
- echo 'zsh2.2/func/proto: original size 194, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/func/randline ==============
- if test -f 'zsh2.2/func/randline' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/func/randline (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/func/randline (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/func/randline' &&
- X# get a random line from a file
- SHAR_EOF
- true || echo 'restore of zsh2.2/func/randline failed'
- fi
- echo 'End of zsh2.2 part 2'
- echo 'File zsh2.2/func/randline is continued in part 3'
- echo 3 > _shar_seq_.tmp
- exit 0
-
- exit 0 # Just in case...
-